package localTests;
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.Vector;

import org.json.*;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.*;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;


public class UseServletTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JSONObject obj = new JSONObject();
		ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String line;
		try{
			obj.put("thought", "this is another test thought by ryan");
			obj.put("shitter", "ryan");
			nameValuePairs.add(new BasicNameValuePair("thought", obj.toString()));
			StringEntity se = new StringEntity("this is a test string");
			MultipartEntity me = new MultipartEntity();
			FileBody fb = new FileBody(new File("C:\\Users\\Ryan\\Pictures\\Facebook\\before.jpg"));
			me.addPart("file",fb);
			HttpClient client = new DefaultHttpClient();
			HttpPost post = new HttpPost("http://localhost:85/HttpTest.php");
			post.setEntity(se);
			System.out.println(post.getRequestLine());
			HttpResponse response = client.execute(post);
			HttpEntity entity = response.getEntity();
			InputStream is = entity.getContent();
			BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
			while((line=reader.readLine())!= null){
				System.out.println(line);
			}
            is.close();
		}
		
		catch (Exception e){
			System.out.println(e.getMessage());
		}
	}
}


